package com.zilu.digitaltwin.entity.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.zilu.digitaltwin.entity.dto.PathNodeDTO;
import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
public class BaseTreeNodeDTO<T> {

    /**
     * 目录树的层级记录  方便前端识别
     * 固定逻辑  level=4为对应的实体
     */
    private Integer  level;

    private List<T> children;

    /**
     * 记录完整路径，包括父实体
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private List<PathNodeDTO> fullPath;

    private String name;
    private String code;
    private String type;
    /**
     * 是否系统编目/实体
     */
    private Boolean system;
    /**
     * record parent code
     */
    private String parent;
    /**
     * 节点扩展信息
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Map<String, Object> extra;

    public BaseTreeNodeDTO() {
    }

    public void add(T child) {
        if (children == null) {
            children = new ArrayList<>();
        }
        children.add(child);
    }

    public void addExtra(String key, Object value) {
        if (extra == null) {
            extra = new HashMap<>(16);
        }
        extra.put(key, value);
    }

}